<%@ WebHandler Language="C#" Class="CoralNode.MvcClient.Themes.CoralAdmin._misc.scripts.ueditor.net.imageManager" %>
/**
 * Created by visual studio2010
 * User: xuheng
 * Date: 12-3-7
 * Time: 下午16:29
 * To change this template use File | Settings | File Templates.
 */
using System;
using System.Linq;
using System.Web;
using System.IO;
using System.Text.RegularExpressions;

namespace CoralNode.MvcClient.Themes.CoralAdmin._misc.scripts.ueditor.net
{
    public class imageManager : IHttpHandler
    {

        public void ProcessRequest(HttpContext context) {
            context.Response.ContentType = "text/plain";

            string[] paths = { UeditorConfig.UEditRootPath }; //需要遍历的目录列表，最好使用缩略图地址，否则当网速慢时可能会造成严重的延时
            string[] filetype = { ".gif", ".png", ".jpg", ".jpeg", ".bmp" };                //文件允许格式

            string action = context.Server.HtmlEncode(context.Request["action"]);

            if (action == "get") {
                String str = String.Empty;

                foreach (string path in paths) {
                    DirectoryInfo info = new DirectoryInfo(context.Server.MapPath(path));

                    //目录验证
                    if (info.Exists) {
                        DirectoryInfo[] infoArr = info.GetDirectories();
                        var files = infoArr.SelectMany(n => n.GetFiles()).ToList().OrderByDescending(n => n.CreationTime);
                        foreach (FileInfo fi in files) {
                            if (Array.IndexOf(filetype, fi.Extension) != -1) {
                                str += path + "/" + fi.Directory.Name + "/" + fi.Name + "ue_separate_ue";
                            }
                        }
                    }
                }

                context.Response.Write(str);
            }
        }


        public bool IsReusable {
            get {
                return false;
            }
        }

    }
}